package pers.kw.feign;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import pers.kw.contants.ServiceNameConstants;
import pers.kw.entity.TokenInfoDto;
import pers.kw.feign.fallback.AuthServerFallbackFactory;
import pers.kw.protocol.R;

@FeignClient(contextId = "authApiService", value = ServiceNameConstants.AUTH_SERVICE,
        fallbackFactory = AuthServerFallbackFactory.class)
public interface AuthApiService {

    /**
     * 申请token
     *
     * @param grantType
     * @param scope
     * @param username
     * @param password
     * @param userType
     * @return
     */
    @PostMapping(value = "/oauth/token")
    R<TokenInfoDto> accessToken(@RequestParam(value = "grant_type") String grantType,
                                @RequestParam(value = "scope") String scope,
                                @RequestParam(value = "username") String username,
                                @RequestParam(value = "password") String password,
                                @RequestParam(value = "userType") String userType);

    /**
     * 刷新token
     *
     * @param grantType
     * @param scope
     * @param username
     * @param userType
     * @param refresh_token
     * @return
     */
    @PostMapping(value = "/oauth/token")
    R<TokenInfoDto> refreshToken(@RequestParam(value = "grant_type") String grantType,
                             @RequestParam(value = "scope") String scope,
                             @RequestParam(value = "username") String username,
                             @RequestParam(value = "userType") String userType,
                             @RequestParam(value = "refresh_token") String refresh_token
    );
}
